package com.lostad.app.vert.web;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.lostad.app.vert.MainVerticle;
import com.lostad.app.vert.util.AppProperties;

import io.vertx.core.Vertx;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;

@RunWith(VertxUnitRunner.class)
public class DbVerticleTest2 {

  private Vertx vertx;

  @Before
  public void setUp(TestContext context) {
    vertx = Vertx.vertx();
    vertx.deployVerticle(MainVerticle.class.getName(), context.asyncAssertSuccess());
  }

  @After
  public void tearDown(TestContext context) {
    vertx.close(context.asyncAssertSuccess());
  }

  @Test
  public void testMyApplication(TestContext context) {
    final Async async = context.async();
    int port = AppProperties.getValue("http.port", 8080);
    System.out.println("================port"+port);
    vertx.createHttpClient().getNow(port, "localhost", "/products",
     response -> {
      response.handler(body -> {
    	String str = body.toString();
    	System.out.println("==========="+str);
        context.assertTrue(str.contains("["));
        async.complete();
      });
    });
  }
}